
package com.ami.kvm.jviewer.kvmpkts;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class IVTPPktHdr {
	public static final int HDR_SIZE = 8;
	public static final int MAX_AVICA_PARAMS = 8;
	public static final int MAX_USERNAME_LEN = 32;
	public static final int STD_DIGEST_LEN = 16;
	public static final int MAX_CHALLENGE_LEN = 32;
	public static final short IVTP_HID_PKT = 1;
	public static final short IVTP_SET_BANDWIDTH = 2;
	public static final short IVTP_SET_FPS = 3;
	public static final short IVTP_PAUSE_REDIRECTION = 4;
	public static final short IVTP_REFRESH_VIDEO_SCREEN = 5;
	public static final short IVTP_RESUME_REDIRECTION = 6;
	public static final short IVTP_SET_COMPRESSION_TYPE = 7;
	public static final short IVTP_STOP_SESSION_IMMEDIATE = 8;
	public static final short IVTP_BLANK_SCREEN = 9;
	public static final short IVTP_GET_USB_MOUSE_MODE = 10;
	public static final short IVTP_GET_FULL_SCREEN = 11;
	public static final short IVTP_ENABLE_ENCRYPTION = 12;
	public static final short IVTP_DISABLE_ENCRYPTION = 13;
	public static final short IVTP_ENCRYPTION_STATUS = 14;
	public static final short IVTP_INITIAL_ENCRYPTION_STATUS = 15;
	public static final short IVTP_BW_DETECT_REQ = 16;
	public static final short IVTP_BW_DETECT_RESP = 17;
	public static final short IVTP_VALIDATE_VIDEO_SESSION = 18;
	public static final short IVTP_VALIDATE_VIDEO_SESSION_RESPONSE = 19;
	public static final short IVTP_GET_KEYBD_LED = 20;
	public static final short IVTP_GET_WEB_TOKEN = 21;
	public static final short IVTP_MAX_SESSION_CLOSING = 22;
	public static final short IVTP_SESSION_ACCEPTED = 23;
	public static final short IVTP_MEDIA_STATE = 24;
	public static final short IVTP_VIDEO_FRAGMENT = 25;
	public static final short IVTP_WEB_PREVIEWER_SESSION = 26;
	public static final short IVTP_WEB_PREVIEWER_CAPTURE_STATUS = 27;
	public static final short IVTP_SET_MOUSE_MODE = 28;
	public static final short IVTP_KVM_SHARING = 32;
	public static final short IVTP_KVM_SOCKET_STATUS = 33;
	public static final short IVTP_POWER_STATUS = 34;
	public static final short IVTP_POWER_CONTROL_REQUEST = 35;
	public static final short IVTP_POWER_CONTROL_RESPONSE = 36;
	public static final short IVTP_CONF_SERVICE_STATUS = 37;
	public static final short IVTP_MOUSE_MEDIA_INFO = 38;
	public static final short IVTP_GET_ACTIVE_CLIENTS = 39;
	public static final byte IVTP_POWER_CONTROL_OFF_IMMEDIATE = 0;
	public static final byte IVTP_POWER_CONTROL_ON = 1;
	public static final byte IVTP_POWER_CONTROL_CYCLE = 2;
	public static final byte IVTP_POWER_CONTROL_HARD_RESET = 3;
	public static final byte IVTP_POWER_CONTROL_SOFT_RESET = 5;
	public static final byte ADVISER_GET_USER_MACRO = 40;
	public static final byte ADVISER_SET_USER_MACRO = 41;
	public static final byte IVTP_IPMI_REQUEST_PKT = 48;
	public static final byte IVTP_IPMI_RESPONSE_PKT = 49;
	public static final byte IVTP_SET_NEXT_MASTER = 50;
	public static final short IVTP_DISPLAY_LOCK_SET = 51;
	public static final short IVTP_DISPLAY_CONTROL_STATUS = 52;
	public static final short IVTP_MEDIA_LICENSE_STATUS = 53;
	public static final short IVTP_KVM_DISCONNECT = 54;
	public static final short IVTP_SET_KBD_LANG = 55;
	public static final short IVTP_MEDIA_FREE_INSTANCE_STATUS = 56;
	public static final short IVTP_KEEP_ALIVE_PKT = 57;
	public static final short IVTP_CONNECTION_COMPLETE_PKT = 58;
	public static final short IVTP_CONNECTION_FAILED = 59;
	public static final short ENCRYPTION_ENABLED = 255;
	public static final byte SESSION_TOKEN_LEN = 16;
	public static final byte WEB_HASH_SIZE = 16;
	public static final short SSI_HASH_SIZE = 130;
	public static final short CLIENT_USERNAME_LENGTH = 129;
	public static final short CLINET_OWN_IP_LENGTH = 65;
	public static final short CLINET_OWN_MAC_LENGTH = 49;
	public static final short VIDEO_PACKET_SIZE = 373;
	public static final byte WEB_SESSION_TOKEN = 0;
	public static final byte SSI_SESSION_TOKEN = 1;
	public short type;
	public int pktSize;
	public short status;
	private ByteBuffer byteBuffer;

	public IVTPPktHdr() {
		this((short) 0, 0, (short) 0);
	}

	public IVTPPktHdr(short type, int pktSize, short status) {
		this.type = type;
		this.pktSize = pktSize;
		this.status = status;
		this.byteBuffer = ByteBuffer.wrap(new byte[HDR_SIZE]);
		this.byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	}

	public void set(ByteBuffer buffer) {
		buffer.order(ByteOrder.LITTLE_ENDIAN);
		buffer.flip();
		this.type = buffer.getShort();
		this.pktSize = buffer.getInt();
		this.status = buffer.getShort();
	}

	public void setSize(int pktSize) {
		this.pktSize = pktSize;
	}

	public void setStatus(short status) {
		this.status = status;
	}

	public short type() {
		return this.type;
	}

	public int pktSize() {
		return this.pktSize;
	}

	public short status() {
		return this.status;
	}

	public int size() {
		return 8;
	}

	public byte[] array() {
		this.byteBuffer.position(0);
		this.byteBuffer.putShort(this.type);
		this.byteBuffer.putInt(this.pktSize);
		this.byteBuffer.putShort(this.status);
		return this.byteBuffer.array();
	}
}